function sumFactors(n) {
    let sum = 1;
    let i = 2;
    for (; i < n / i; i++) {
        if (n % i === 0) {
            sum += i + n / i;

        }
    }
    if (i * i === n) sum += i;
    return sum;
}

function isNonAbundantNumber(n) {
    return n < sumFactors(n);
}

function sumOfNonAbundantNumbers(n) {
    let dp = new Array(n + 1).fill(0);
    let dp2 = new Array(n + 1).fill(0);
    for (let i = 1; i <= n; i++) {
        if (isNonAbundantNumber(i)) dp[i] = 1;
    }
    //console.log(dp);

    for (let i = 1; i <= n; i++) {
        for (let j = 1; j <= n - i; j++) {
            if (dp[i] && dp[j])
                dp2[i + j] = 1;
        }
    }
    //console.log(dp2);
    let sum = 0;
    for (let i = 0; i <= n; i++) {
        if (dp2[i] === 0) sum += i;
    }
    return sum;
}

console.log(sumOfNonAbundantNumbers(28123));